<% page_title "Kubernetes Releases" %>

<%= render 'projects/header', project: @project, tab: 'kubernetes' %>

<section class="tabs kubernetes-section">
  <%= render 'samson_kubernetes/role_navigation' %>

  <table class="table table-condensed">
    <thead>
      <tr>
        <th>Id</th>
        <th>Deploy</th>
        <th>Build</th>
        <th>Deploy Groups</th>
        <th>Created</th>
        <th>Created By</th>
      </tr>
    </thead>
    <tbody>
      <% if @kubernetes_releases.empty? %>
        <tr>
          <td colspan="5">No releases have been created yet.</td>
        </tr>
      <% else %>
        <% @kubernetes_releases.each do |kubernetes_release| %>
          <tr>
            <td>
              <%= link_to "#{kubernetes_release.id}#{" - #{kubernetes_release.blue_green_color}" if kubernetes_release.blue_green_color}", project_kubernetes_release_path(@project, kubernetes_release) %>
            </td>
            <td>
              <% if kubernetes_release.deploy %>
                <%= link_to status_badge(kubernetes_release.deploy.job.status), project_deploy_path(@project, kubernetes_release.deploy) %>
              <% else %>
                Not deployed.
              <% end %>
            </td>
            <td>
              <%= link_to "Build", project_builds_path(@project, search: {git_sha: kubernetes_release.git_sha}) %>
            </td>
            <td>
              <% DeployGroup.with_deleted { kubernetes_release.release_docs.map(&:deploy_group) }.uniq.sort_by(&:natural_order).each do |deploy_group| %>
                 <span class="label label-info"><%= deploy_group.name %></span>
              <% end %>
            </td>
            <td><%= kubernetes_release.created_at %></td>
            <td><%= kubernetes_release.user.name %></td>
          </tr>
        <% end %>
      <% end %>
    </tbody>
  </table>
</section>
